import numpy as np
import cv2 as cv

# 创建2*2照片
img = np.zeros((2, 2, 3), np.uint8)
b, g, r = cv.split(img)

# 图片1 [150 100 10]
b[:] = 0xa
g[:] = 0x2a
r[:] = 0xba
img1 = cv.merge([b, g, r])
cv.imshow("img1", img1)
# cv.waitKey(0)

# 图片2 [10 100 150]
b[:] = 0xba
g[:] = 0x2a
r[:] = 0xa
img2 = cv.merge([b, g, r])
cv.imshow("img2", img2)
# cv.waitKey(0)

# 计算图片1 and 图片2
img_bit_and = cv.bitwise_and(img1, img2)
cv.imshow("img_bit_and", img_bit_and)
print("img_bit_and", img_bit_and)

# 计算图片1 or 图片2
img_bit_or = cv.bitwise_or(img1, img2)
cv.imshow("img_bit_or", img_bit_or)
print("img_bit_or", img_bit_or)

# 计算图片1 not 图片2
img_bit_not = cv.bitwise_not(img1, img2)
cv.imshow("img_bit_not", img_bit_not)
print("img_bit_not", img_bit_not)

# 计算图片1 xor 图片2
img_bit_xor = cv.bitwise_xor(img1, img2)
cv.imshow("img_bit_xor", img_bit_xor)
print("img_bit_xor", img_bit_xor)

cv.waitKey(0)
cv.destroyAllWindows()